{extend name="layout" /}
{block name="content"}
<div class="layui-tab layui-tab-brief">
	<ul class="layui-tab-title">
	    <li class="layui-this">{$pathCurrent['name']}</li>
	    <li><a href="{:url('option')}">添加域名</a></li>
  	</ul>
</div>
<div class="fileBox" style="margin-top: 25px;margin-left:20px;">

</div>

<div class="demoTable" style="margin-top: 25px;margin-left:20px;">
	域名：
	<div class="layui-inline" style="width:250px;">
		<input class="layui-input" name="title" id="title" placeholder="搜索域名" autocomplete="off">
	</div>
	
<!--	<div class="layui-inline">-->
<!--		<form class="layui-form">-->
<!--			<select class="layui-input" name="jump" id="jump" lay-filter="cid">-->
<!--				<option value="">是否劫持</option>-->
<!--				<option value="1">开</option>-->
<!--				<option value="0">关</option>-->
<!--				-->
<!--			</select>-->
<!--		</form>-->
<!--	</div>-->
	<button class="layui-btn" data-type="reload">搜索</button>
</div>
<div class="layui-card-body">
	<div data-model="table-bind">
		<table class="layui-hide" id="data_table" lay-filter="data_table" data-table></table>
	</div>
</div>
<script type="text/html" id="barTar">
	<a class="layui-btn layui-btn-xs" href="{{d.op}}">编辑</a>
  	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" data-del data-id="{{d.id}}" data-table="staff">删除</a>
</script>
<script type="text/html" id="image">
	<img src="{{d.image}}" height="30">
</script>
<script type="text/html" id="sysTar">
	{{#  if(d.jump == 1){ }}
  	<button type="button" lay-event="status" data-id="{{d.id}}" class="layui-btn layui-btn-normal">正常</button>
  	{{#  } else { }}
  	<button type="button" lay-event="status" data-id="{{d.id}}" class="layui-btn layui-btn-danger">关闭</button>
  	{{#  } }}
</script>
{/block}
{block name="js"}
<script type="text/javascript">
var mixin = {};
var SlefUrl = this.location.href;
layui.use(['table','upload'], function(){
	var table = layui.table
		,upload = layui.upload;
	table.render({
		elem: '#data_table',
		url:SlefUrl,
		limit:20,
		cellMinWidth: 80,
		cols: [[
	      	{field:'id',width:80, title: 'ID', sort: true,align:'center'}
			,{field:'tg_url', title: '推广域名',align:'center'}
			,{field:'tz_url', title: '跳转域名',align:'center'}
			,{field:'jump_url', title: '跳转域名限制',align:'center'}
			,{field:'kill_addr', title: '限制地区',align:'center'}
			,{field:'day_limit', title: '每天限制点击次数',align:'center'}
			,{field:'is_mobile', title: '手机跳转限制',align:'center'}
	      	// ,{field:'jump', title: '劫持状态',toolbar: '#sysTar'}
	      	,{field:'op', title: '操作',toolbar: '#barTar', width:150,align:'center'}
	    ]],
	    page: true,
        id: 'testReload'
	});
	table.on('tool(data_table)', function(obj){
		var data = obj.data;
		data.table = "scurl";
		if(obj.event === 'del'){
			layer.confirm('确定删除吗？', function(index){
	        	layer.close(index);
	       		form.formDel(data,obj);
	      	});
		}

		if(obj.event === 'status'){
			layer.confirm('确定修改状态吗？', function(index){
						var result = {};
						result = data;
	       		$.post('{:url("status")}',result,function(res){
								if( res.code == 1 ){
									window.location.reload();
								}else{
									alert(res.msg);
								}
						 },'json')
	    });
		}

	});
    var $ = layui.$, active = {
        reload: function(){
            var title = $('#title');
            var jump = $('#jump');

            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    title: title.val()
                    ,jump: jump.val()
                }
            }, 'data');
        },
		excelDemo: function(){
            window.location.href = '/excel/staff_demo.xls'
        }
    };

	upload.render({
		elem: '#uploadExcel'
		,url: '{:url("savestudentImport")}'
		,accept: 'file' //普通文件
		,auto:'xlsx|xls|csv'
		,done: function(res){
			layer.alert(res.msg);
			// setInterval(function(){
			// 	window.location.reload();
			// },3000)
			
		}
	});



    $('.demoTable .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

	$('#excelDemo').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });


});
</script>
{/block}